package com.mwm.paiwei.meiye.config;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import com.lianjiao.core.CoreConfig;
import com.lianjiao.core.database.DatabaseHelper;
import com.mwm.paiwei.meiye.database.User;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MeiYeConfig extends CoreConfig {

    public static long USERID = 1;
    //    正试
//          public static String url = "http://work.yanyur.com/";
    //    测试
    public static String url = "http://beautywork.companycn.net/";

    //;"file:///sdcard/meiye/index/";

    public static User user;
    public static float JS_VERSION ;
    public static String JS_DOWNLOAD_URL = "";
    public static String FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "meiye";

    //"file:///mnt/sdcard/meiye/index/";
    public static String local_url = Environment.getExternalStorageDirectory()
            .getAbsolutePath() +  File.separator +"meiye" + File.separator +"index";

    //获取文件md5值
    public static String getFileMD5(File file) throws NoSuchAlgorithmException, IOException {
        if (!file.isFile()) {
            Log.e("tests3333","hehe");
            return null;
        }
        MessageDigest digest;
        FileInputStream in;
        byte buffer[] = new byte[1024];
        int len;
        digest = MessageDigest.getInstance("MD5");
        in = new FileInputStream(file);
        while ((len = in.read(buffer, 0, 1024)) != -1) {
            digest.update(buffer, 0, len);
        }
        in.close();
        BigInteger bigInt = new BigInteger(1, digest.digest());
        return bigInt.toString(16);
    }

    public MeiYeConfig(final Context context) {
        // 基础配置
        CoreConfig.DBName = "meiye.db";
        CoreConfig.folderRoot = "meiyeConfig";


        // 创建数据库，并且建立表
        DatabaseHelper.getHelper(context).createTable(User.class);

        // 创建界面demo1
//        List<AppMenu> menus = new ArrayList<>();
//        List<AppPage> pages = new ArrayList<>();
        // 菜单
//        menus.add(new AppMenu("美业", R.drawable.ic_launcher, R.drawable.ic_launcher));
//        menus.add(new AppMenu("页面2", R.drawable.ic_tab_record_normal, R.drawable.ic_tab_record_selected));
//        menus.add(new AppMenu("页面3", R.drawable.ic_tab_user_normal, R.drawable.ic_tab_user_selected));
        // 界面
//        pages.add(new AppPage(new MainFrag()));
//        pages.add(new AppPage(new TestFrag2()));
//        pages.add(new AppPage(new TestFrag3()));
        // 全部创建界面
//        AppFrame.getAppFrame().createAppFrame(menus, pages);
        // 底部样式设置
//        AppFrame.getAppFrame().footLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
//                LayoutParams.WRAP_CONTENT);
        // 底部菜单分割线是否显示
//        AppFrame.getAppFrame().isShowSplitLine = true;
        // 设置菜单位置
//        CoreConfig.menuPos = MenusPosition.TOP;
        // 设置菜单不显示图片
//        CoreConfig.menusWithoutText = true;
        // 设置菜单不显示文字
//        CoreConfig.menusWithoutImg = true;

        // 主界面切换监听
//        AppFrame.getAppFrame().changePageListener = (new ChangePageListener() {
//
//            @Override
//            public void changePage(int what, BaseFragment frag) {
//                LsToast.show(context, "主页切换 what = " + what + " frag = " + frag.getClass().getSimpleName());
//                if (what == 1) {
//                    AppFrame.getAppFrame().isShowMsgTip(what, false);
//                }
//            }
//        });

    }

}
